{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "443ee010-3164-4a6f-bfb2-bcca28a934de",
   "metadata": {},
   "outputs": [],
   "source": [
    "import polars as pl\n",
    "from perspective.widget import PerspectiveWidget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "900578fe-7985-4a2f-8e70-5cd8f1505a31",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "d1 = pl.read_parquet(\"new_share.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e605f6c2-f7cf-4223-9e83-b9e4ac32c095",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2 = pl.read_parquet(\"stock_basic.parquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c2a143b1-c9a2-4f1d-a8f5-3f78aeb41be9",
   "metadata": {},
   "outputs": [],
   "source": [
    "d1 = d1.with_columns(\n",
    "    ipo_date=pl.col.ipo_date.str.to_date(\"%Y%m%d\"),\n",
    "    issue_date=pl.col.issue_date.str.to_date(\"%Y%m%d\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ea427795-b2c8-4ae6-997b-8179086ee01a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "d2 = d2.with_columns(\n",
    "    list_date=pl.col.list_date.str.to_date(\"%Y%m%d\"),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "341c4bbf-acc5-4bc3-ba11-97e9b85c0967",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "polars.dataframe.frame.DataFrame"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "cb4fbe61-19e2-4fbf-a201-077582da336c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "polars.dataframe.frame.DataFrame"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8dffec4d-d514-4140-873d-cffb1782af4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "config = '{\"version\":\"3.5.1\",\"plugin\":\"Datagrid\",\"plugin_config\":{\"columns\":{},\"edit_mode\":\"READ_ONLY\",\"scroll_lock\":false},\"columns_config\":{},\"settings\":true,\"theme\":\"Pro Light\",\"title\":null,\"group_by\":[],\"split_by\":[],\"sort\":[[\"amount\",\"asc\"]],\"filter\":[],\"expressions\":{},\"columns\":[\"ts_code\",\"sub_code\",\"name\",\"ipo_date\",\"issue_date\",\"amount\",\"market_amount\",\"price\",\"pe\",\"limit_amount\",\"funds\",\"ballot\"],\"aggregates\":{}}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c8ba7ed0-3985-4063-9a14-7115479b7479",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"version\":\"3.5.1\",\"plugin\":\"Datagrid\",\"plugin_config\":{\"columns\":{},\"edit_mode\":\"READ_ONLY\",\"scroll_lock\":false},\"columns_config\":{},\"settings\":true,\"theme\":\"Pro Light\",\"title\":null,\"group_by\":[],\"split_by\":[],\"sort\":[[\"amount\",\"asc\"]],\"filter\":[],\"expressions\":{},\"columns\":[\"ts_code\",\"sub_code\",\"name\",\"ipo_date\",\"issue_date\",\"amount\",\"market_amount\",\"price\",\"pe\",\"limit_amount\",\"funds\",\"ballot\"],\"aggregates\":{}}\n"
     ]
    }
   ],
   "source": [
    "print(config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "ce8f1c31-f203-48c8-a7fc-df49c62558a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ddaaa1c-ae31-4b03-9cfd-e79775033e84",
   "metadata": {},
   "outputs": [],
   "source": [
    "config2 = Path(\"C:/Users/16386/Downloads/untitled.config.json\"),read_text(encoding=\"utf8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eae1ff25-f1cd-4b35-bd99-6631194f4eee",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(config2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "272d988b-3320-443e-939e-0f2c804e0127",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7b5c23f-4338-4e29-a574-d47a3f1d8c4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "json.loads(config2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10f39a53-80d2-49df-a498-dd1b25c24190",
   "metadata": {},
   "outputs": [],
   "source": [
    "PerspectiveWidget(\n",
    "    d1,\n",
    "    expressions={\n",
    "        \"上网发行比例\":'\"market amount\"/\"amount\",\n",
    "        'price_cent':'\"price\" * 100',\n",
    "    }\n",
    ")       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1902c84d-ec81-4454-873e-7dbc9130aec1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f15cca7e1a6c49649aa0df5cfd2ddc62",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "PerspectiveWidget(binding_mode='server', columns=['ts_code', 'symbol', 'name', 'area', 'industry', 'fullname',…"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PerspectiveWidget(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "791affe8-b553-4411-b4d6-4011a3bd4a29",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
